
/* ************************************************************************************* 
 * CREATED BY:          MYGENERATION
 * CREATED DATE:        12/25/2008
 * PROJECT:             MCWEBSITE
 * PURPOSE:             websiteProductCategoryDAL class
 * MODIFIED BY:         None
 * MODIFIED DATE:       None
 * MODIFIED REASON:     None
 * NOTES:               None
 **************************************************************************************/
 
using System;
using System.Collections.Generic;
using System.Text;
using System.Collections;
using System.Configuration;
using System.Data.SqlClient;
using Microsoft.ApplicationBlocks.Data;
using System.Web.Configuration;
using MCWEBSITE.ENTITY;

namespace MCWEBSITE.DAL
{
    public class websiteProductCategoryDAL
    {
        #region  Properties
		 
		public static string FIELD_CATEGORYID = "CategoryID";  
		public static string FIELD_LANGUAGECODE = "LanguageCode";  
		public static string FIELD_CATEGORYCODE = "CategoryCode";  
		public static string FIELD_CATEGORYNAME = "CategoryName";  
		public static string FIELD_DESCRIPTION = "Description";  
		public static string FIELD_PARENTCATEGORYID = "ParentCategoryID";  
		public static string FIELD_ATRIBUTE1 = "Atribute1";  
		public static string FIELD_ATRIBUTE2 = "Atribute2";  
		public static string FIELD_ATRIBUTE3 = "Atribute3"; 
		public static string ConnectionString = System.Web.Configuration.WebConfigurationManager.ConnectionStrings["ContentConnectionString"].ToString();

        #endregion

        #region Protected methods

        /// <summary>
        /// Select entity of websiteProductCategory
        /// </summary>
        /// <param name="CategoryID">Primary Keys</param>
        /// <returns>Collection of websiteProductCategoryInfo</returns>
        public static websiteProductCategoryInfo SelectOne(int CategoryID)
        {
            websiteProductCategoryInfo _websiteProductCategoryInfo = new websiteProductCategoryInfo();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteProductCategorySelectOne", CategoryID);
                if (dr.Read())
                    setwebsiteProductCategoryInfo(dr, ref _websiteProductCategoryInfo);
                return _websiteProductCategoryInfo;
            }
            catch (Exception ex)
            {
                throw;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="LanguageCode"></param>
        /// <returns></returns>
        public static List<websiteProductCategoryInfo> SelectAllParent()
        {
            List<websiteProductCategoryInfo> lstwebsiteProductCategory = new List<websiteProductCategoryInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteParentProductCategorySelectAll");
                setListwebsiteProductCategoryInfo(ref dr, ref lstwebsiteProductCategory);
                return lstwebsiteProductCategory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        public static List<websiteProductCategoryInfo> SelectOtherParents(int categoryId)
        {
            List<websiteProductCategoryInfo> lstwebsiteProductCategory = new List<websiteProductCategoryInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteProductCategorySelectOtherParents", categoryId);
                setListwebsiteProductCategoryInfo(ref dr, ref lstwebsiteProductCategory);
                return lstwebsiteProductCategory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="LanguageCode"></param>
        /// <returns></returns>
        public static List<websiteProductCategoryInfo> SelectParentByLanguageCode(string LanguageCode)
        {
            List<websiteProductCategoryInfo> lstwebsiteProductCategory = new List<websiteProductCategoryInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteParentProductCategorySelectByLanguageCode", LanguageCode);
                setListwebsiteProductCategoryInfo(ref dr, ref lstwebsiteProductCategory);
                return lstwebsiteProductCategory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// 
        /// </summary>
        /// <param name="LanguageCode"></param>
        /// <param name="CategoryID"></param>
        /// <returns></returns>
        public static List<websiteProductCategoryInfo> SelectCategoryByLangAndParent(string LanguageCode, string CategoryID)
        {
            List<websiteProductCategoryInfo> lstwebsiteProductCategory = new List<websiteProductCategoryInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteProductCategorySelectByLangAndParent", LanguageCode, CategoryID);
                setListwebsiteProductCategoryInfo(ref dr, ref lstwebsiteProductCategory);
                return lstwebsiteProductCategory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        public static List<websiteProductCategoryInfo> SelectCategoryByLangAndParent(string LanguageCode, int CategoryID)
        {
            List<websiteProductCategoryInfo> lstwebsiteProductCategory = new List<websiteProductCategoryInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteProductCategorySelectByLangAndParent1", LanguageCode, CategoryID);
                setListwebsiteProductCategoryInfo(ref dr, ref lstwebsiteProductCategory);
                return lstwebsiteProductCategory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        
        /// <summary>
        /// Select all websiteProductCategory
        /// </summary>
        /// <returns>Collection of websiteProductCategoryInfo</returns>
        public static List<websiteProductCategoryInfo> SelectAll()
        {
            List<websiteProductCategoryInfo> lstwebsiteProductCategory = new List<websiteProductCategoryInfo>();
            SqlDataReader dr = null;
            try
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteProductCategorySelectAll");
                setListwebsiteProductCategoryInfo(ref dr, ref lstwebsiteProductCategory);
                return lstwebsiteProductCategory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Select
        /// </summary>
        /// <param name="websiteProductCategorynfo">Modify this method adapting your need</param>
        /// <returns>Collection of websiteProductCategoryInfo</returns>
        public static List<websiteProductCategoryInfo> SelectFilters(string strLanguage)
        {
            string criterias = string.Empty;
            List<websiteProductCategoryInfo> lstwebsiteProductCategory = new List<websiteProductCategoryInfo>();
            SqlDataReader dr = null;
            try 
            {
                dr = SqlHelper.ExecuteReader(ConnectionString, "sp_mc_websiteProductCategorySelectByFilters", strLanguage);
                setListwebsiteProductCategoryInfo(ref dr, ref lstwebsiteProductCategory);
                return lstwebsiteProductCategory;
            }
            catch (Exception ex)
            {
                throw ex;
            }
            finally
            {
                dr.Close();
            }
        }

        /// <summary>
        /// Insert websiteProductCategory
        /// </summary>
        /// <param name="websiteProductCategoryInfo">Entity of websiteProductCategory</param>
        /// <returns>error code</returns>
        public static int Insert(websiteProductCategoryInfo _websiteProductCategoryInfo)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteProductCategoryInsert" 
											, _websiteProductCategoryInfo.CategoryID
                                            , _websiteProductCategoryInfo.LanguageCode
											, _websiteProductCategoryInfo.CategoryCode
											, _websiteProductCategoryInfo.CategoryName
											, _websiteProductCategoryInfo.Description
                                            , _websiteProductCategoryInfo.ParentCategoryID
											, _websiteProductCategoryInfo.Atribute1
											, _websiteProductCategoryInfo.Atribute2
											, _websiteProductCategoryInfo.Atribute3
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }
        
        /// <summary>
        /// Update websiteProductCategory
        /// </summary>
        /// <param name="websiteProductCategoryInfo">Entity of websiteProductCategory</param>
        /// <returns>error code</returns>
        public static int Update(websiteProductCategoryInfo _websiteProductCategoryInfo)
        {            
            try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteProductCategoryUpdate"
											, _websiteProductCategoryInfo.CategoryID
											, _websiteProductCategoryInfo.LanguageCode
											, _websiteProductCategoryInfo.CategoryCode
											, _websiteProductCategoryInfo.CategoryName
											, _websiteProductCategoryInfo.Description
											, _websiteProductCategoryInfo.ParentCategoryID
											, _websiteProductCategoryInfo.Atribute1
											, _websiteProductCategoryInfo.Atribute2
											, _websiteProductCategoryInfo.Atribute3
											);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        /// <summary>
        /// Delete SchoolAdmin
        /// </summary>
        /// <param name="CategoryID">Primary Key</param>
        /// <returns>error code</returns>
        public static int Delete(int CategoryID)
        {
           try
            {
                SqlHelper.ExecuteNonQuery(ConnectionString, "sp_mc_websiteProductCategoryDelete", CategoryID);
                return 1;
            }
            catch (Exception ex)
            {
                return -1;
            }
        }

        #endregion

        #region "Utilities method"
		
        private static void setListwebsiteProductCategoryInfo(ref SqlDataReader dr, ref List<websiteProductCategoryInfo> lstwebsiteProductCategory)
        {
            websiteProductCategoryInfo _websiteProductCategoryInfo = null;
            while (dr.Read())
            {
                _websiteProductCategoryInfo = new websiteProductCategoryInfo();
                setwebsiteProductCategoryInfo(dr, ref _websiteProductCategoryInfo);
                lstwebsiteProductCategory.Add(_websiteProductCategoryInfo);
            }
        }

        private static void setwebsiteProductCategoryInfo(SqlDataReader dr, ref websiteProductCategoryInfo _websiteProductCategoryInfo)
        {
            _websiteProductCategoryInfo.CategoryID = dr[websiteProductCategoryDAL.FIELD_CATEGORYID] != DBNull.Value ? Convert.ToInt32(dr[websiteProductCategoryDAL.FIELD_CATEGORYID]) : 0;
			_websiteProductCategoryInfo.LanguageCode = dr[websiteProductCategoryDAL.FIELD_LANGUAGECODE] != DBNull.Value ? Convert.ToString(dr[websiteProductCategoryDAL.FIELD_LANGUAGECODE]) : string.Empty;
			_websiteProductCategoryInfo.CategoryCode = dr[websiteProductCategoryDAL.FIELD_CATEGORYCODE] != DBNull.Value ? Convert.ToString(dr[websiteProductCategoryDAL.FIELD_CATEGORYCODE]) : string.Empty;
			_websiteProductCategoryInfo.CategoryName = dr[websiteProductCategoryDAL.FIELD_CATEGORYNAME] != DBNull.Value ? Convert.ToString(dr[websiteProductCategoryDAL.FIELD_CATEGORYNAME]) : string.Empty;
			_websiteProductCategoryInfo.Description = dr[websiteProductCategoryDAL.FIELD_DESCRIPTION] != DBNull.Value ? Convert.ToString(dr[websiteProductCategoryDAL.FIELD_DESCRIPTION]) : string.Empty;
            _websiteProductCategoryInfo.ParentCategoryID = dr[websiteProductCategoryDAL.FIELD_PARENTCATEGORYID] != DBNull.Value ? Convert.ToInt32(dr[websiteProductCategoryDAL.FIELD_PARENTCATEGORYID]) : 0;
			_websiteProductCategoryInfo.Atribute1 = dr[websiteProductCategoryDAL.FIELD_ATRIBUTE1] != DBNull.Value ? Convert.ToString(dr[websiteProductCategoryDAL.FIELD_ATRIBUTE1]) : string.Empty;
			_websiteProductCategoryInfo.Atribute2 = dr[websiteProductCategoryDAL.FIELD_ATRIBUTE2] != DBNull.Value ? Convert.ToString(dr[websiteProductCategoryDAL.FIELD_ATRIBUTE2]) : string.Empty;
			_websiteProductCategoryInfo.Atribute3 = dr[websiteProductCategoryDAL.FIELD_ATRIBUTE3] != DBNull.Value ? Convert.ToString(dr[websiteProductCategoryDAL.FIELD_ATRIBUTE3]) : string.Empty;
			                        
        }
        #endregion Methods

        #region Private Members

        private static string TABLE_NAME = "[mc_websiteProductCategory]";

        #endregion
    }
}

		